<template>
  <DetailsFormBox :title="dataInfo?.table?.title" :type="route.query.type" :form="data.form" :btns="[
    {
      title: '重置',
      icon: '',
      type: '',
      click: getForm,
    },
    {
      title: '保存',
      icon: '',
      type: 'primary',
      click: (form: any) => {
        saveBtn(form)
      },
    },
  ]" :loading="data.loading" :json="dataInfo">
    <template #default="{ form }">
      <div class="formMain">
        <ElFormItemBox label="规则编号" :prop="`productMapQuickOrderingCode`">
          <ElInputBox :data="form.productMapQuickOrderingCode" disabled placeholder="系统自动生成" />
        </ElFormItemBox>
        <ElFormItemBox label="导入列名" :prop="`columnName`" isRules>
          <ElInputBox :data="form" dataName="columnName" />
        </ElFormItemBox>
        <ElFormItemBox label="导入列值" :prop="`columnValue`" isRules>
          <ElInputBox :data="form" dataName="columnValue" />
        </ElFormItemBox>
        <ElFormItemBox label="关联产品" :prop="`productCode`" isRules>
          <ElSelectBox :data="form" dataName="productCode" :options="options.product" />
        </ElFormItemBox>
      </div>
    </template>
  </DetailsFormBox>
</template>
<script setup lang="ts">
import { useListComponent } from '../pageTs'; // 引入逻辑
const { dataInfo } = useListComponent();
import { reactive, onMounted, getCurrentInstance } from 'vue';
const { proxy } = getCurrentInstance() as any;
const data = reactive({
  loading: false,
  loadingMsg: '',
  form: {
    productMapQuickOrderingCode: "", // 匹配规则唯一编码
    columnName: "", // 要匹配的列名
    columnValue: "", // 要匹配的列值
    productCode: "", // 要匹配的列值
  },
  fileCodes: []
});
import { useRoute } from 'vue-router';
// 获取当前路由对象
const route = useRoute();


import { sendMsg } from '@/utils/crossTagMag.ts';
const saveBtn = (form: any) => {
  if (form.productMapQuickOrderingID) {
    proxy.$api.OrderBusniess.UpdateProductMapQuickOrdering(form)
      .then((res: any) => {
        _sun()
      })
      .catch(() => { });
  } else {
    proxy.$api.OrderBusniess.AddProductMapQuickOrdering(form)
      .then((res: any) => {
        _sun()
      })
      .catch(() => { });
  }

  function _sun() {
    proxy.$message('保存成功')
    sendMsg('save', true);
    // getForm()
    window.close();
  }
};
const getForm = () => {
  let _query: any = route.query
  if (_query.productMapQuickOrderingID) {
    data.form = _query
  }

};
import { getProduct } from '@/utils/optionsArr.ts';
const options = reactive({
  product: [],
})
onMounted(() => {
  getForm();
  getProduct(options, 'product') //获取所有产品
});
</script>
